package com.yst.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yst.common.core.domain.entity.SysDept;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yst.common.annotation.Log;
import com.yst.common.core.controller.BaseController;
import com.yst.common.core.domain.AjaxResult;
import com.yst.common.enums.BusinessType;
import com.yst.system.domain.BasItemType;
import com.yst.system.service.IBasItemTypeService;
import com.yst.common.utils.poi.ExcelUtil;

/**
 * 产品类型Controller
 * 
 * @author hoj
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/system/itemType")
public class BasItemTypeController extends BaseController {
    @Autowired
    private IBasItemTypeService basItemTypeService;

    /**
     * 查询产品类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public AjaxResult list(BasItemType basItemType)
    {
        List<BasItemType> list = basItemTypeService.selectBasItemTypeList(basItemType);
        return success(list);
    }

    /**
     * 导出产品类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "产品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasItemType basItemType)
    {
        List<BasItemType> list = basItemTypeService.selectBasItemTypeList(basItemType);
        ExcelUtil<BasItemType> util = new ExcelUtil<BasItemType>(BasItemType.class);
        util.exportExcel(response, list, "产品类型数据");
    }

    /**
     * 获取产品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{itemTypeId}")
    public AjaxResult getInfo(@PathVariable("itemTypeId") Long itemTypeId)
    {
        return success(basItemTypeService.selectBasItemTypeByItemTypeId(itemTypeId));
    }

    /**
     * 新增产品类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "产品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasItemType basItemType)
    {
        return toAjax(basItemTypeService.insertBasItemType(basItemType));
    }

    /**
     * 修改产品类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "产品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasItemType basItemType)
    {
        return toAjax(basItemTypeService.updateBasItemType(basItemType));
    }

    /**
     * 删除产品类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "产品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemTypeIds}")
    public AjaxResult remove(@PathVariable Long[] itemTypeIds)
    {
        return toAjax(basItemTypeService.deleteBasItemTypeByItemTypeIds(itemTypeIds));
    }

    /**
     * 获取部门树列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/itemTypeTree")
    public AjaxResult basItemTypeTree(BasItemType itemType)
    {
        return success(basItemTypeService.selectItemTypeTreeList(itemType));
    }
}
